package com.zzxx.exam.util;

import java.io.FileInputStream;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.Properties;

/**
 * Config 读取系统的配置文件
 */
public class Config {
    private Properties pro = new Properties();

    public Config(String file) {
        try {
//            pro.load(new FileInputStream(file));

//            pro.load(Files.newInputStream(Paths.get("src/com/zzxx/exam/util/client.properties")));
            pro.load(Files.newInputStream(Paths.get("src/com/zzxx/exam/util/" + file)));

//            pro.load(Files.newInputStream(Paths.get(file)));
//            String filePath = Config.class.getResource("client.properties").getPath();
//            pro.load(Files.newInputStream(Paths.get(filePath)));
        } catch (IOException e) {
            e.printStackTrace();
            throw new RuntimeException(e);
        }
    }

    public int getInt(String key) {
        return Integer.parseInt(pro.getProperty(key));
    }

    public String getString(String key) {
        return pro.getProperty(key);
    }

    public Double getDouble(String key) {
        return Double.parseDouble(pro.getProperty(key));
    }
}